//获取应用实例
const app = getApp()
var CONFIG = require("../../config/config.js");
Page({
  data: {
    admin_id: 0,
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    tel:'',
    tuifalse: false
  },

  // 点击退出登录
  tuiclick: function () {
    this.setData({
      tuifalse: true
    })
  },
  // 点击退出登录  取消
  noclick: function () {
    this.setData({
      tuifalse: false
    })
  },

  // 点击退出登录  确定
  yesclick: function () {
    this.setData({
      tuifalse: false
    })
    wx.removeStorage({
      key: 'tel',
      success: function () {
        wx.showToast({
          title: '退出登录成功',
          icon: 'none',
          duration: 1500
        })

        setTimeout(function () {
          wx.redirectTo({
            url: '../login',
          })
        }, 300)
      },
      fail: function () {
        wx.showModal({
          title: CONFIG.MODEL_TITLE,
          showCancel: false,
          content: CONFIG.REQUEST_FAIL,
          confirmText: '点击重试',
          success: function (res) {
            wx.navigateBack();
          }
        })
      }
    })
  },
 
  onLoad: function (options) {
    // console.log(options);
    var globalData = JSON.parse(options.options);
    var tel = globalData.tel;

    this.setData({
      user_id: globalData.uid,
      admin_id: globalData.admin_id,
      userInfo: globalData.userInfo,
      hasUserInfo: true,
      tel: tel.replace(tel.substr(3, 4), "****")
    })
  },

  onShow: function() {
    
  },
  
  // 用户点击右上角分享

  onShareAppMessage: function () {
    return {
      title: CONFIG.SHARETITLE,
      path: CONFIG.PATHLOGIN
    }
  },
  

  getUserInfo: function(e) {
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})